<template>
	<view class="bar">
		<view class="example-body">
			<view class="left">
				<uni-icons type="back" size="30" color="#73767a"  @click="goBack" v-if="allowBack"/>
				<image class="img" src="/static/logo1.png" @click="personal"></image>
				<text class="headline" v-if="title">{{title}}</text>
				
			</view>
			<view class="right">
				<image src="/static/icons/search.png" class="img-icon"></image>
				<image src="/static//icons/scan.png" @click="scanCode" class="img-icon"></image>
			</view>
			
		</view>
	</view>
	
</template>

<script>
	export default {
		name: "navigationBar-top",
		props: {
            allowBack:{
                type: Boolean,
                default: false
            },
			title:{
				type: String,
				default: ''
			}
        },
		data() {
			return {
				isShow: false,
				scanMenu: false,
				scanlist: [{
						title: "打印机二维码",
						type: 'printer',
						id: 1
					},
					{
						title: "服务器、电脑二维码",
						type: 'CPU',
						id: 2
					},
					{
						title: "车辆二维码",
						type: 'car',
						id: 3
					},
					{
						title: "产品二维码",
						type: 'product',
						id: 4
					},
				]
			}
		},
		methods: {
			openMenu() {
				this.isShow = !this.isShow

				if (this.scanMenu) {
					setTimeout(() => {
						this.scanMenu = !this.scanMenu
					}, 200)
				} else {
					setTimeout(() => {
						this.scanMenu = !this.scanMenu
					}, 200)
				}
			},
			goBack() {
				uni.navigateBack()
			},
			scanCode() {
				uni.navigateTo({
					// url: '/pages/scan/printer?deviceNumber=4546'
					url: '/pages/scan/car?carCodeNumber=湘EF069'
				})
				// uni.scanCode({
				// 	success: (res) => {
				// 		this.result = JSON.parse(res.result);
				// 		this.scanDetail(Number(this.result.type));
				// 	},
				// 	fail: (err) => {
				// 		console.error('扫码失败', err);
				// 	}
				// });
			},
			scanDetail(e) {
				switch (e) {
					case 0:
						uni.navigateTo({
							url: '/pages/scan/printer?deviceNumber=' + this.result.deviceNumber
						})
						break;
					case 1:
						uni.navigateTo({
							url: '/pages/scan/printer?id=' + e
						})
						break;
					case 2:
						uni.navigateTo({
							url: '/pages/scan/printer?id=' + e
						})
						break;
					case 3:
						uni.navigateTo({
							url: '/pages/scan/car?carCodeNumber=' + this.result.carCodeNumber
						})
						break;
					case 4:
						uni.navigateTo({
							url: '/pages/scan/product?id=' + e
						})
						break;
					default:
						console.log("没有匹配的类型")
						break;
				}
			},
			gotoScan() {
				uni.navigateTo({
					url: '/pages/scan/scan-succeed'
				})
			},
			personal() {
				uni.navigateTo({
					url: '/pages/user/user'
				})
			}
		},
		
	}
</script>

<style lang="less" scoped>
	.bar
	{
		width: 100vw;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: center;
		box-sizing: border-box;
		background: rgb(246, 249, 254);
		.example-body {
				display: flex;
				justify-content: space-between;
				align-items: center;
				width: 90vw;
				height: 100rpx;
				margin-top: 70rpx;
				box-sizing: border-box;
				.left {
					display: flex;
					flex-direction: row;
					align-items: center;
					justify-content: flex-start;
					gap: 10rpx;
					.headline {
						width: 280rpx;
						height: 80rpx;
						font-weight: 500;
						font-size: 40rpx;
						text-align: center;
						line-height: 80rpx;
						color: #000000;
						letter-spacing: 2px;
					}
					.img {
						width: 98rpx;
						height: 52rpx;
					}
				}
				.right
				{
					display: flex;
					flex-direction: row;
					align-items: center;
					justify-content: flex-end;
					gap: 20rpx;
					
							
					.img-icon {
						width: 50rpx;
						height: 50rpx;
					}
				}
				
				
			}
		
			
			
				
	}
	</style>